﻿/*
 * @Author       : xiaoyuan-cloud 1805980417@qq.com
 * @Date         : 2024-10-21 09:49:30
 * @LastEditors  : xiaoyuan-cloud 1805980417@qq.com
 * @LastEditTime : 2024-10-21 19:11:41
 * @FilePath     : \J1939\J1939\j1939_config.h
 * @Description  : SAE_J1939协议栈底层接口配置
 * SPDX-License-Identifier: MIT
 * Copyright (c) 2024 by xiaoyuan-cloud, All Rights Reserved.
 */
#ifndef _J1939_CONFIG_H
#define _J1939_CONFIG_H

#include "j1939.h"

 /***************************J1939 地址配置*****************************/
 // 设备默认的地址（地址命名是有规定的，参考J1939的附录B 地址和标识符的分配）
#define J1939_STARTING_ADDRESS_1 0x56	// CAN1本机节点地址
#define J1939_STARTING_ADDRESS_2 0x56	// CAN2本机节点地址
#define J1939_STARTING_ADDRESS_3 0xA0	// CAN3本机节点地址
#define J1939_STARTING_ADDRESS_4 0		// CAN4本机节点地址

/*CAN发送&&接收回调接口*/
typedef struct
{
	int (*can_send_data)(CAN_NODE can_port, j1939_uint8_t* pbuf, j1939_uint32_t buf_len, j1939_uint32_t ExdID);										   // 发送接口
	int (*can_add_rx_callback)(CAN_NODE can_port, void (*pCallbacks)(const j1939_uint32_t id, const j1939_uint8_t* buf, const j1939_uint32_t buflen)); // 接收回调
} CAN_PORT_FUNC;

/*CAN底层接口初始化*/
void J1939_Config_Init(int (*can_send_data)(CAN_NODE can_port, j1939_uint8_t* pbuf, j1939_uint32_t buf_len, j1939_uint32_t ExdID),
	int (*can_add_rx_callback)(CAN_NODE can_port, void (*pCallbacks)(const j1939_uint32_t id, const j1939_uint8_t* buf, const j1939_uint32_t buflen)));

/*j1939协议栈收发接口*/
int J1939_CAN_Transmit(CAN_NODE port, const J1939_MESSAGE* pthis);
int J1939_CAN_Receive(CAN_NODE port, J1939_MESSAGE* pthis);

#endif // !_J1939_CONFIG_H
